{% set pypi_name = 'ironic' %}
{% set source = fetch_source('https://tarballs.openstack.org/ironic/ironic-master.tar.gz') %}
{% set upstream_version = upstream_version() %}
{% set rpm_release = '1' %}
%global with_doc 1
%if 0%{?rhel} || 0%{?fedora}
%global rdo 1
%endif
Name:           {{ py2name() }}
Epoch:          {{ epoch('ironic') }}
Version:        {{ py2rpmversion() }}
Release:        {{ py2rpmrelease() }}
Summary:        Openstack Provisioning of Bare Metal Servers
License:        {{ license('Apache-2.0') }}
URL:            https://docs.openstack.org/ironic
Source0:        {{ source|basename }}
Source1:        openstack-ironic.sudoers
Source2:        openstack-ironic.logrotate
Source3:        openstack-ironic.tmpfiles
Source4:        openstack-ironic.defaultconf
Source5:        openstack-ironic.README.config
# systemd service files
Source6:        openstack-ironic-api.service
Source7:        openstack-ironic-conductor.service
BuildRequires:  openstack-macros
BuildRequires:  {{ py3('Jinja2') }}
BuildRequires:  {{ py3('SQLAlchemy') }}
BuildRequires:  {{ py3('WebOb') }}
BuildRequires:  {{ py3('alembic') }}
BuildRequires:  {{ py3('automaton') }}
BuildRequires:  {{ py3('python-cinderclient') }}
BuildRequires:  {{ py3('ddt') }}
BuildRequires:  {{ py3('eventlet') }}
BuildRequires:  {{ py3('fixtures') }}
BuildRequires:  {{ py3('futurist') }}
BuildRequires:  {{ py3('python-glanceclient') }}
BuildRequires:  {{ py3('ironic-lib') }}
BuildRequires:  {{ py3('iso8601') }}
BuildRequires:  {{ py3('jsonpatch') }}
BuildRequires:  {{ py3('jsonschema') }}
BuildRequires:  {{ py3('keystoneauth1') }}
BuildRequires:  {{ py3('keystonemiddleware') }}
BuildRequires:  {{ py3('mock') }}
BuildRequires:  {{ py3('python-neutronclient') }}
BuildRequires:  {{ py3('openstacksdk') }}
BuildRequires:  {{ py3('os-traits') }}
BuildRequires:  {{ py3('oslo.concurrency') }}
BuildRequires:  {{ py3('oslo.config') }}
BuildRequires:  {{ py3('oslo.context') }}
BuildRequires:  {{ py3('oslo.db') }}
BuildRequires:  {{ py3('oslo.i18n') }}
BuildRequires:  {{ py3('oslo.log') }}
BuildRequires:  {{ py3('oslo.messaging') }}
BuildRequires:  {{ py3('oslo.middleware') }}
BuildRequires:  {{ py3('oslo.policy') }}
BuildRequires:  {{ py3('oslo.reports') }}
BuildRequires:  {{ py3('oslo.rootwrap') }}
BuildRequires:  {{ py3('oslo.serialization') }}
BuildRequires:  {{ py3('oslo.service') }}
BuildRequires:  {{ py3('oslo.upgradecheck') }}
BuildRequires:  {{ py3('oslo.utils') }}
BuildRequires:  {{ py3('oslo.versionedobjects') }}
BuildRequires:  {{ py3('oslotest') }}
BuildRequires:  {{ py3('osprofiler') }}
BuildRequires:  {{ py3('pbr') }}
BuildRequires:  {{ py3('pecan') }}
BuildRequires:  {{ py3('psutil') }}
BuildRequires:  {{ py3('pysendfile') }}
BuildRequires:  {{ py3('pysnmp') }}
BuildRequires:  {{ py3('pytz') }}
BuildRequires:  {{ py3('requests') }}
BuildRequires:  {{ py3('retrying') }}
BuildRequires:  {{ py3('rfc3986') }}
BuildRequires:  {{ py3('stestr') }}
BuildRequires:  {{ py3('stevedore') }}
BuildRequires:  {{ py3('python-swiftclient') }}
BuildRequires:  {{ py3('testtools') }}
BuildRequires:  {{ py3('tooz') }}
BuildRequires:  sudo
Requires:       logrotate
Requires:       python3-{{ pypi_name }} = %{epoch}:%{version}-%{release}
BuildArch:      noarch
%if 0%{?suse_version}
BuildRequires:  systemd-rpm-macros
%{?systemd_requires}
%else
BuildRequires:  systemd
Requires(post): systemd
Requires(postun): systemd
Requires(pre):  shadow-utils
Requires(preun): systemd
%endif

%description
Ironic is an Incubated OpenStack project which aims to provision bare metal
machines instead of virtual machines, forked from the Nova Baremetal driver.
It is best thought of as a bare metal hypervisor API and a set of plugins
which interact with the bare metal hypervisors. By default, it will use
PXE and IPMI in concert to provision and turn on/off machines, but Ironic
also supports vendor-specific plugins which may implement additional functionality.

%package -n     python3-{{ pypi_name }}
Summary:        OpenStack shared file system service (ironic) - Python module
Group:          Development/Languages/Python
Requires:       {{ py3('Jinja2') }}
Requires:       {{ py3('SQLAlchemy') }}
Requires:       {{ py3('WebOb') }}
Requires:       {{ py3('alembic') }}
Requires:       {{ py3('automaton') }}
Requires:       {{ py3('python-cinderclient') }}
Requires:       {{ py3('eventlet') }}
Requires:       {{ py3('futurist') }}
Requires:       {{ py3('python-glanceclient') }}
Requires:       {{ py3('ironic-lib') }}
Requires:       {{ py3('jsonpatch') }}
Requires:       {{ py3('jsonschema') }}
Requires:       {{ py3('keystoneauth1') }}
Requires:       {{ py3('keystonemiddleware') }}
Requires:       {{ py3('python-neutronclient') }}
Requires:       {{ py3('openstacksdk') }}
Requires:       {{ py3('os-traits') }}
Requires:       {{ py3('oslo.concurrency') }}
Requires:       {{ py3('oslo.config') }}
Requires:       {{ py3('oslo.context') }}
Requires:       {{ py3('oslo.db') }}
Requires:       {{ py3('oslo.log') }}
Requires:       {{ py3('oslo.messaging') }}
Requires:       {{ py3('oslo.middleware') }}
Requires:       {{ py3('oslo.policy') }}
Requires:       {{ py3('oslo.rootwrap') }}
Requires:       {{ py3('oslo.serialization') }}
Requires:       {{ py3('oslo.service') }}
Requires:       {{ py3('oslo.upgradecheck') }}
Requires:       {{ py3('oslo.utils') }}
Requires:       {{ py3('oslo.versionedobjects') }}
Requires:       {{ py3('osprofiler') }}
Requires:       {{ py3('pbr') }}
Requires:       {{ py3('pecan') }}
Requires:       {{ py3('psutil') }}
Requires:       {{ py3('pysendfile') }}
Requires:       {{ py3('pytz') }}
Requires:       {{ py3('requests') }}
Requires:       {{ py3('retrying') }}
Requires:       {{ py3('rfc3986') }}
Requires:       {{ py3('stevedore') }}
Requires:       {{ py3('python-swiftclient') }}
Requires:       {{ py3('tooz') }}
Requires:       sudo

%description -n python3-{{ pypi_name }}
This package contains the core code of OpenStack Ironic.

%if 0%{?with_doc}
%package doc
Summary:        OpenStack bare metal provisioning service (ironic) - Documentation
Group:          Documentation/HTML
BuildRequires:  {{ py3('Sphinx') }}
BuildRequires:  {{ py3('openstackdocstheme') }}
BuildRequires:  {{ py3('sphinxcontrib-apidoc') }}
BuildRequires:  {{ py3('sphinxcontrib-httpdomain') }}
BuildRequires:  {{ py3('sphinxcontrib-pecanwsme') }}
BuildRequires:  {{ py3('sphinxcontrib-seqdiag') }}
BuildRequires:  {{ py3('sphinxcontrib-svg2pdfconverter') }}

%description doc
OpenStack bare metal provisioning service.
This package contains the Documentation.
%endif

%package api
Summary:        OpenStack Ironic - API
Group:          System/Management
Requires:       openstack-{{ pypi_name }} = %{epoch}:%{version}-%{release}

%description api
This package contains the OpenStack Ironic API Daemon.

%package conductor
Summary:        OpenStack Ironic - Conductor
Group:          System/Management
Requires:       openstack-{{ pypi_name }} = %{epoch}:%{version}-%{release}

%description conductor
This package contains the OpenStack Ironic Conductor Manager Daemon.

%prep
%autosetup -p1 -n {{ pypi_name }}-{{ upstream_version }}
%py_req_cleanup

%build
%{py3_build}

%if 0%{?with_doc}
PYTHONPATH=. PBR_VERSION={{ upstream_version }} %sphinx_build --keep-going -b html doc/source doc/build/html
PYTHONPATH=. PBR_VERSION={{ upstream_version }} %sphinx_build --keep-going -b man doc/source doc/build/man
# remove the Sphinx-build leftovers
rm -rf doc/build/html/.{doctrees,buildinfo}
rm -rf doc/build/man/.{doctrees,buildinfo}
%endif

%install
%{py3_install}

### Setup directories
install -d -m 750 %{buildroot}%{_localstatedir}/{lib,log,cache}/ironic
install -d -m 755 %{buildroot}%{_sysconfdir}/ironic
install -d -m 755 %{buildroot}%{_sysconfdir}/ironic/ironic.conf.d/
install -d -m 700 %{buildroot}%{_localstatedir}/run/ironic

### Install configuration files
install -D -m 644 %{SOURCE3} %{buildroot}/%_tmpfilesdir/ironic.conf
install -p -D -m 640 %{SOURCE4} %{buildroot}%{_sysconfdir}/ironic/ironic.conf.d/010-ironic.conf
mv %{buildroot}%{_prefix}%{_sysconfdir}/ironic/* %{buildroot}%{_sysconfdir}/ironic/
cp -a etc/ironic/rootwrap.d/ %{buildroot}%{_sysconfdir}/ironic/
install -p -D -m 640 %{SOURCE5} %{buildroot}%{_sysconfdir}/ironic/README.config

### Install systemd service files
install -p -D -m 644 %{SOURCE6} %{buildroot}%{_unitdir}/%{name}-api.service
install -p -D -m 644 %{SOURCE7} %{buildroot}%{_unitdir}/%{name}-conductor.service

### install symlinks on SUSE
%if 0%{?suse_version}
mkdir -p %{buildroot}%{_sbindir}
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}-api
ln -s %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name}-conductor
%endif

### sudoers configuration for ironic-rootwrap:
install -D -m 440 %{SOURCE1} %{buildroot}%{_sysconfdir}/sudoers.d/openstack-ironic

### Install logrotate
install -p -D -m 644 %{SOURCE1} %{buildroot}%{_sysconfdir}/logrotate.d/openstack-ironic

### man pages
%if 0%{?with_doc}
mkdir -p %{buildroot}%{_mandir}/man1
install -p -D -m 644 doc/build/man/*.1 %{buildroot}%{_mandir}/man1/
%endif

%check
export LC_ALL=en_US.UTF-8
python3 -m stestr.cli run

%pre
%openstack_pre_user_group_create ironic ironic /sbin/nologin
exit 0

%post
%tmpfiles_create %{_tmpfilesdir}/ironic.conf

%post api
%systemd_post %{name}-api.service

%preun api
%systemd_preun %{name}-api.service

%postun api
%systemd_postun %{name}-api.service

%post conductor
%systemd_post %{name}-conductor.service

%preun conductor
%systemd_preun %{name}-conductor.service

%postun conductor
%systemd_postun %{name}-conductor.service

%files
%doc README.rst
%license LICENSE
%dir %attr(0750, ironic, ironic) %{_localstatedir}/lib/ironic
%dir %attr(0750, ironic, ironic) %{_localstatedir}/cache/ironic
%dir %attr(0750, ironic, ironic) %{_localstatedir}/log/ironic
%_tmpfilesdir/ironic.conf
%dir %{_sysconfdir}/ironic
%dir %{_sysconfdir}/ironic/ironic.conf.d/
%{_sysconfdir}/ironic/README.config
%config(noreplace) %{_sysconfdir}/logrotate.d/openstack-ironic
%config(noreplace) %{_sysconfdir}/sudoers.d/openstack-ironic
%config(noreplace) %attr(0640, root, ironic) %{_sysconfdir}/ironic/ironic.conf.d/010-ironic.conf
%config %{_sysconfdir}/ironic/rootwrap.conf
%dir %{_sysconfdir}/ironic/rootwrap.d
%config(noreplace) %{_sysconfdir}/ironic/rootwrap.d/ironic-utils.filters
%{_bindir}/ironic-status
%{_bindir}/ironic-rootwrap
%{_bindir}/ironic-dbsync
%if 0%{?with_doc}
%{_mandir}/man1/ironic.1.gz
%endif

%files -n python3-ironic
%license LICENSE
%{python3_sitelib}/ironic/
%{python3_sitelib}/ironic-*.egg-info

%files doc
%license LICENSE
%doc doc/build/html

%files api
%license LICENSE
%{_unitdir}/%{name}-api.service
%if 0%{?suse_version}
%{_sbindir}/rc%{name}-api
%endif
%{_bindir}/ironic-api
%{_bindir}/ironic-api-wsgi

%files conductor
%license LICENSE
%{_unitdir}/%{name}-conductor.service
%if 0%{?suse_version}
%{_sbindir}/rc%{name}-conductor
%endif
%{_bindir}/ironic-conductor

%changelog
